package com.aq.sales.controller.admin;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.aq.sales.business.intf.LookupBO;
import com.aq.sales.business.intf.OppBO;
import com.aq.sales.business.intf.TestBO;
import com.aq.sales.entity.Lookup;
import com.aq.sales.entity.Opportunity;
import com.aq.sales.entity.OwnerHistory;
import com.aq.sales.entity.StateHistory;

@Controller
@RequestMapping("/login")
public class LoginController {
	protected final Log logger = LogFactory.getLog(getClass());
	public LookupBO<Lookup> lookupBO;
	public TestBO<Lookup> testBO;
	public OppBO<Lookup> oppBO;
	
	public LoginController() {
	}
	
	public TestBO<Lookup> getTestBO() {
		return testBO;
	}

	@Autowired
	public void setTestBO(TestBO<Lookup> testBO) {
		this.testBO = testBO;
	}
	
	public LookupBO<Lookup> getLookupBO() {
		return lookupBO;
	}

	@Autowired
	public void setLookupBO(LookupBO<Lookup> lookupBO) {
		this.lookupBO = lookupBO;
	}
	
	@RequestMapping(value="/tst.do",method = RequestMethod.GET)
	public ModelAndView tst(HttpServletRequest request, ModelAndView model,HttpSession session) {
		System.out.println("Testing X000014............."+lookupBO.findAll(1));
		Lookup l=lookupBO.findById(1);
		l.setDescription("NEW DESC1");
		lookupBO.update(l);
		System.out.println("Testing X000014............."+lookupBO.findAll(1));
		 model.setViewName("/jsp/tst.jsp");
		 model.addObject("props", lookupBO.findAll(1));
			return model;
	}
	
	@RequestMapping(value="/tst1.do",method = RequestMethod.GET)
	public ModelAndView tst1(HttpServletRequest request, ModelAndView model,HttpSession session) {
		System.out.println("Testing X000024............."+lookupBO.findAll(1));
		testBO.insert(new Lookup(0,1,"DESC LK","LOOKUP",0,"India"),true);
		System.out.println("Testing X000024............."+lookupBO.findAll(1));
		 model.setViewName("/jsp/tst.jsp");
			return model;
	}
	
	@RequestMapping(value="/t2.do",method = RequestMethod.GET)
	public ModelAndView t2(HttpServletRequest request, ModelAndView model,HttpSession session) {
		System.out.println("Inserting opp X00001.............");
		Opportunity p=new Opportunity(0, 1, 1,1, new Date(), new Date(),1, "first opp", (byte) 0,1, "first opp nae", "folow", 1,1, 1, 12,1, new Date(),1);
		StateHistory sh=new StateHistory(0, 1, 1, "Open",1,new Date(), 1);
		OwnerHistory oh=new OwnerHistory(0, "vishnu", 1, 1,1,new Date(), 1);
		oppBO.insert(p,sh,oh);
		 model.setViewName("/jsp/tst.jsp");
			return model;
	}
	public OppBO<Lookup> getOppBO() {
		return oppBO;
	}
	@Autowired
	public void setOppBO(OppBO<Lookup> oppBO) {
		this.oppBO = oppBO;
	}
}
